From 3f2ecb4a42d30a1865ea22ce7b305618adb26951 Mon Sep 17 00:00:00 2001 From: Ben Wiederhake Date: Wed, 5 Apr 2017 21:48:15 +0200 Subject: [PATCH] AllKinds tests: cargo-test --- tests/test.rs | 132 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/tests/test.rs b/tests/test.rs index 66c2e9c41..a63380519 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1252,6 +1252,41 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ")); } +#[test] +fn test_run_implicit_bin_target() { + let prj = project("foo") + .file("Cargo.toml" , r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [[bin]] + name="mybin" + path="src/mybin.rs" + "#) + .file("src/mybin.rs", "#[test] fn test_in_bin() { } + fn main() { panic!(\"Don't execute me!\"); }") + .file("tests/mytest.rs", "#[test] fn test_in_test() { }") + .file("benches/mybench.rs", "#[test] fn test_in_bench() { }") + .file("examples/myexm.rs", "#[test] fn test_in_exm() { } + fn main() { panic!(\"Don't execute me!\"); }"); + + assert_that(prj.cargo_process("test").arg("--bins"), + execs().with_status(0) + .with_stderr(format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[RUNNING] target[/]debug[/]deps[/]mybin-[..][EXE]", dir = prj.url())) + .with_stdout(" +running 1 test +test test_in_bin ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + +")); +} + #[test] fn test_run_specific_test_target() { let prj = project("foo") @@ -1281,6 +1316,103 @@ test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured ")); } +#[test] +fn test_run_implicit_test_target() { + let prj = project("foo") + .file("Cargo.toml" , r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [[bin]] + name="mybin" + path="src/mybin.rs" + "#) + .file("src/mybin.rs", "#[test] fn test_in_bin() { } + fn main() { panic!(\"Don't execute me!\"); }") + .file("tests/mytest.rs", "#[test] fn test_in_test() { }") + .file("benches/mybench.rs", "#[test] fn test_in_bench() { }") + .file("examples/myexm.rs", "#[test] fn test_in_exm() { } + fn main() { panic!(\"Don't execute me!\"); }"); + + assert_that(prj.cargo_process("test").arg("--tests"), + execs().with_status(0) + .with_stderr(format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[RUNNING] target[/]debug[/]deps[/]mytest-[..][EXE]", dir = prj.url())) + .with_stdout(" +running 1 test +test test_in_test ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + +")); +} + +#[test] +fn test_run_implicit_bench_target() { + let prj = project("foo") + .file("Cargo.toml" , r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [[bin]] + name="mybin" + path="src/mybin.rs" + "#) + .file("src/mybin.rs", "#[test] fn test_in_bin() { } + fn main() { panic!(\"Don't execute me!\"); }") + .file("tests/mytest.rs", "#[test] fn test_in_test() { }") + .file("benches/mybench.rs", "#[test] fn test_in_bench() { }") + .file("examples/myexm.rs", "#[test] fn test_in_exm() { } + fn main() { panic!(\"Don't execute me!\"); }"); + + assert_that(prj.cargo_process("test").arg("--benches"), + execs().with_status(0) + .with_stderr(format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..] +[RUNNING] target[/]debug[/]deps[/]mybench-[..][EXE]", dir = prj.url())) + .with_stdout(" +running 1 test +test test_in_bench ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured + +")); +} + +#[test] +fn test_run_implicit_example_target() { + let prj = project("foo") + .file("Cargo.toml" , r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + + [[bin]] + name="mybin" + path="src/mybin.rs" + "#) + .file("src/mybin.rs", "#[test] fn test_in_bin() { } + fn main() { panic!(\"Don't execute me!\"); }") + .file("tests/mytest.rs", "#[test] fn test_in_test() { }") + .file("benches/mybench.rs", "#[test] fn test_in_bench() { }") + .file("examples/myexm.rs", "#[test] fn test_in_exm() { } + fn main() { panic!(\"Don't execute me!\"); }"); + + assert_that(prj.cargo_process("test").arg("--examples"), + execs().with_status(0) + .with_stderr(format!("\ +[COMPILING] foo v0.0.1 ({dir}) +[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]", dir = prj.url()))); +} + #[test] fn test_no_harness() { let p = project("foo") -- 2.30.2